package com.wuyan.web.base.api;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wuyan.web.base.aop.ApiLogAnnotation;
import com.wuyan.web.base.entity.PubFunction;
import com.wuyan.web.base.helper.BaseApi;
import com.wuyan.web.base.helper.rep.RepBody;
import com.wuyan.web.base.helper.rep.RepCodeEnum;
import com.wuyan.web.base.helper.rep.RepHelper;
import com.wuyan.web.base.service.PubFormService;
import com.wuyan.web.base.service.PubFormServiceExtend;
import com.wuyan.web.base.service.PubFunctionServiceExtend;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 扩展接口
 */

@Slf4j
@RestController
@RequestMapping("/api/pub-form")
public class PubFormApiExtend extends BaseApi implements RepHelper {
    @Autowired
    private PubFormServiceExtend pubFormService;

    /**
     * 更新表单对应的流程信息
     *
     * @param id       id
     * @param flowId   流程ID
     * @param flowName 流程名称
     * @return RepBody<Long>
     */
    @PutMapping("/{id}/up-flow/{flowId}/{flowName}")
    @ApiLogAnnotation(name = "PubForm:up-flow")
    @Transactional(rollbackFor = Exception.class)
    public RepBody<Long> upFlow(
            @PathVariable("id") Integer id,
            @PathVariable("flowId") String flowId,
            @PathVariable("flowName") String flowName
    ) throws Exception {
        long update = pubFormService.upFlow(id, flowId, flowName);
        return update > 0 ? ok(update) : error(RepCodeEnum.ERR_UPDATE);
    }
}